package io.renren.modules.erp.controller;

import java.util.Arrays;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.common.validator.ValidatorUtils;
import io.renren.modules.erp.entity.CustomerInfoEntity;
import io.renren.modules.erp.service.CustomerInfoService;



/**
 * 
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2018-07-19 22:30:09
 */
@RestController
@RequestMapping("erp/customerinfo")
public class CustomerInfoController {
    @Autowired
    private CustomerInfoService customerInfoService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("erp:customerinfo:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = customerInfoService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{customerInfoId}")
    @RequiresPermissions("erp:customerinfo:info")
    public R info(@PathVariable("customerInfoId") Long customerInfoId){
        CustomerInfoEntity customerInfo = customerInfoService.selectById(customerInfoId);

        return R.ok().put("customerInfo", customerInfo);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("erp:customerinfo:save")
    public R save(@RequestBody CustomerInfoEntity customerInfo){
        customerInfoService.insert(customerInfo);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("erp:customerinfo:update")
    public R update(@RequestBody CustomerInfoEntity customerInfo){
        ValidatorUtils.validateEntity(customerInfo);
        customerInfoService.updateAllColumnById(customerInfo);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("erp:customerinfo:delete")
    public R delete(@RequestBody Long[] customerInfoIds){
        customerInfoService.deleteBatchIds(Arrays.asList(customerInfoIds));

        return R.ok();
    }

}
